package com.tanhua.controller;

import com.tanhua.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;
    /**
     * 添加联系人
     * POST/messages/contacts
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        Long userId = Long.parseLong(map.get("userId").toString()) ;
        return messageService.contacts(userId);
    }
    /**
     * GET/messages/contacts
     * 联系人列表
     */
    @GetMapping("/contacts")
    public ResponseEntity people(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 @RequestParam(required = false) String keyword){
        return messageService.people(page,pagesize);
    }

    /**
     * GET/messages/likes
     * 点赞列表
     */
    @GetMapping("/likes")
    public ResponseEntity likeList(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize){
        return messageService.likeList(page,pagesize,1);
    }

    /**
     * GET/messages/comments
     * 文字评论列表
     */
    @GetMapping("/comments")
    public ResponseEntity commentsList(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize){
        return messageService.likeList(page,pagesize,2);
    }

    /**
     * GET/messages/loves
     * 喜欢列表
     */
    @GetMapping("/loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize){
        return messageService.likeList(page,pagesize,3);
    }

}
